/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.imenu.ejb;

import com.imenu.entity.ImenuMenu;
import com.imenu.entity.ImenuStore;
import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

/**
 *
 * @author Yunzi
 */
@Stateless
public class ImenuMenuFacade extends AbstractFacade<ImenuMenu> {

    @PersistenceContext(unitName = "iMenuPU")
    private EntityManager em;

    protected EntityManager getEntityManager() {
        return em;
    }

    public ImenuMenuFacade() {
        super(ImenuMenu.class);
    }
    public List<ImenuMenu> findByIds(List<Integer> idList) {
        return getEntityManager().createQuery(
                "select t from ImenuMenu t where t.id in (:idList)").setParameter("idList", idList).getResultList();
    }
    
    public List<ImenuMenu> findByStore(ImenuStore store) {
        return getEntityManager().createQuery(
                "select t from ImenuMenu t where t.store = :store").setParameter("store", store).getResultList();
    }
    
    
    public List<ImenuMenu> findFavorite(String deviceId){
        System.out.println("ImenuMenuFacade.findFavorite() deviceId = "+deviceId);
        return getEntityManager().createQuery(
                "select t from ImenuMenu t where t.id in (select f.menuId from ImenuFavorite f where f.customerId = (select c.id from ImenuCustomer c where c.deviceId = :deviceId))").setParameter("deviceId", deviceId).getResultList();
    }
}
